package org.mat.ipaas.ucenter.bff.admin.config.shiro;

import lombok.extern.slf4j.Slf4j;
import org.mat.ipaas.ucenter.service.api.open.SystemApiRestAPI;
import org.mat.ipaas.ucenter.service.dto.system.vo.LoginUserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * 底层共通业务API，提供其他独立模块调用
 * @Author: scott
 * @Date:2019-4-20 
 * @Version:V1.0
 */
@Slf4j
@Service
public class SysBaseApiImpl implements CommonAPI {

	@Autowired
	private SystemApiRestAPI systemApiRestAPI;

	@Override
	//@SensitiveDecode
	public LoginUserDTO getUserByName(String username) {
		LoginUserDTO userByName = systemApiRestAPI.getUserByName(username);

//TODO 解密
//		//update-begin-author:taoyan date:2022-6-6 for: VUEN-1276 【v3流程图】测试bug 1、通过我发起的流程或者流程实例，查看历史，流程图预览问题
//		if (oConvertUtils.isEmpty(username)) {
//			return null;
//		}
//		//update-end-author:taoyan date:2022-6-6 for: VUEN-1276 【v3流程图】测试bug 1、通过我发起的流程或者流程实例，查看历史，流程图预览问题
//		LoginUserDTO user = sysUs.getEncodeUserInfo(username);
//
//		//相同类中方法间调用时脱敏解密 Aop会失效，获取用户信息太重要，此处采用原生解密方法，不采用@SensitiveDecodeAble注解方式
//		try {
//			SensitiveInfoUtil.handlerObject(user, false);
//		} catch (IllegalAccessException e) {
//			e.printStackTrace();
//		}

		return userByName;
	}

	/**
	 * 查询用户拥有的角色集合 common api 里面的接口实现
	 * @param username
	 * @return
	 */
	@Override
	public Set<String> queryUserRoles(String username) {
		Set<String> strings = systemApiRestAPI.queryUserRoles(username);
		return strings;
	}

	/**
	 * 查询用户拥有的权限集合 common api 里面的接口实现
	 * @param username
	 * @return
	 */
	@Override
	public Set<String> queryUserAuths(String username) {
		Set<String> strings = systemApiRestAPI.queryUserAuths(username);
		return strings;
	}

}